import { Injectable } from '@angular/core';
import { HttpClient,HttpHeaders } from '@angular/common/http';

@Injectable({
  providedIn: 'root'
})
export class HeroService {
  public headers: HttpHeaders = new HttpHeaders({ 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'});

  constructor(private http: HttpClient) { 
  }

  get(url:string){
    return this.http.get(url,{headers:this.headers})
    .toPromise()
    .then(response => JSON.parse(JSON.stringify(response)))
    .catch((err) => console.log(err));
  }

  post(url:string,params:any){
    return this.http.post(url,params,{headers:this.headers})
    .toPromise()
    .then(response => JSON.parse(JSON.stringify(response)))
    .catch((err) => console.log(err));
  }
}